package be.ipl.eBar.domaine;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

@SuppressWarnings("serial")
@Entity
@Table(name = "COMMANDES", schema = "EBAR")
public class Commande implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;
	@NotNull
	@Temporal(TemporalType.DATE)
	private Calendar date;
	@ManyToMany
	@JoinTable(name = "COMMANDES_BIERES", schema = "EBAR", joinColumns = { @JoinColumn(name = "COMMANDE_ID") }, inverseJoinColumns = { @JoinColumn(name = "NOM_BIERE", referencedColumnName="nom") })
	private List<Biere> bieres = new ArrayList<Biere>();
	
	protected Commande() {
	}

	public Commande(Calendar date) {
		date.set(Calendar.HOUR, 0);
		date.set(Calendar.MINUTE, 0);
		date.set(Calendar.SECOND, 0);
		date.set(Calendar.MILLISECOND, 0);
		this.date = date;
	}

	public int getId() {
		return id;
	}
	
	public Calendar getDate() {
		return date;
	}
	
	public List<Biere> getBieres() {
		return bieres;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Commande other = (Commande) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
	
	
}
